package org.geo.common.response;

import org.geo.common.response.model.JsonResponse;

/**
 * 向前端返回信息的类
 *
 * @author ljy
 */
public class Responser {
    /**
     * 返回成功的信息
     *
     * @param message    提示消息
     * @param result     结果
     * @param totalCount 结果数量
     * @return Response
     */
    public static JsonResponse success(String message, Object result, Integer totalCount) {
        JsonResponse jsonResponse = new JsonResponse();
        return jsonResponse.statusCode(ResponseConstants.OK).message(message).totalCount(totalCount).result(result);
    }

    /**
     * 返回成功的信息
     *
     * @param message 提示消息
     * @param result  结果
     * @return Response
     */
    public static JsonResponse success(String message, Object result) {
        JsonResponse jsonResponse = new JsonResponse();
        return jsonResponse.statusCode(ResponseConstants.OK).message(message).totalCount(null).result(result);
    }

    /**
     * 返回成功的信息
     *
     * @param message 提示消息
     * @return Response
     */
    public static JsonResponse success(String message) {
        JsonResponse jsonResponse = new JsonResponse();
        return jsonResponse.statusCode(ResponseConstants.OK).message(message).totalCount(null).result(null);
    }

    /**
     * 返回成功的信息
     *
     * @param result 结果
     * @return Response
     */
    public static JsonResponse success(Object result) {
        JsonResponse jsonResponse = new JsonResponse();
        return jsonResponse.statusCode(ResponseConstants.OK).message(null).totalCount(null).result(result);
    }

    /**
     * 返回失败的信息
     *
     * @param message 提示消息
     * @return Response
     */
    public static JsonResponse failed(String message) {
        JsonResponse jsonResponse = new JsonResponse();
        return jsonResponse.statusCode(ResponseConstants.EXCEPTION_FAILED).message(message).totalCount(null).result(null);
    }

    public static JsonResponse serverError(String message) {
        JsonResponse jsonResponse = new JsonResponse();
        return jsonResponse.statusCode(ResponseConstants.SERVER_ERROR).message(message).totalCount(null).result(null);
    }
}
